﻿using System;

namespace WriteLog
{
    /// <summary>
    /// 描述一个日志项
    /// </summary>
    public class BaseLogMessage
    {
        /// <summary>
        /// 构造函数
        /// 设定日志项产生的时间
        /// </summary>
        public BaseLogMessage()
        {
            this._dateTime = DateTime.Now;
        }

        /// <summary>
        /// 用于存储日志项产生的时间
        /// </summary>
        private DateTime? _dateTime;

        /// <summary>
        /// 需要记录日志项的级别
        /// LogLevel枚举
        /// </summary>
        public virtual LogLevel Level { get; set; }

        /// <summary>
        /// 日志项产生的时间
        /// </summary>
        public DateTime dateTime 
        {
            get
            {
                return _dateTime.Value;
            }
        }

        /// <summary>
        /// 日志项的来源
        /// </summary>
        public virtual string Provider { get; set; }

        /// <summary>
        /// 产生日志项的ID
        /// </summary>
        public virtual int EventID { get; set; }

        /// <summary>
        /// 产生日志项的任务名称
        /// </summary>
        public virtual string TaskName { get; set; }

        /// <summary>
        /// 产生日志项的内容
        /// </summary>
        public virtual string MessageBody { get; set; }

        /// <summary>
        /// 重写ToString方法
        /// 目的：方便获取格式字符串
        /// 在派生类中同样可以重写
        /// </summary>
        /// <returns>格式后的日志项字符串</returns>
        public override string ToString()
        {
            //{日期}\t{级别}\t{来源}\t{ID}\t{任务名称}\t{日志项内容};
            return string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", this.dateTime, this.Level, this.Provider, this.EventID, this.TaskName, this.MessageBody);
        }
    }
}
